function generatorWrapper(genFn) {
  return function(...args) {
    const gen = genFn.apply(this, args)
    return new Promise((resolve, reject) => {
      function next(key, arg) {
        let info;
        try {
          info = gen[key](arg);
        } catch (e) {
          return reject(e);
        }
        if (info.done) {
          return resolve(info.value);
        } else {
          return Promise.resolve(info.value).then(
            res => next('next', res),
            err => next('throw', err)
          )
        }
      }
      next('next');
    })
  }
}

const fetchData1 = () => {
  return new Promise(resolve => {
    setTimeout(() => resolve(
      'data1'
    ), 1000);
  })
}

const fetchData2 = () => {
  return new Promise((resolve, reject) => {
    setTimeout(() => reject(
      'data2'
    ), 1000);
  })
}

const fetchData3 = () => {
  return new Promise(resolve => {
    setTimeout(() => resolve(
      'data3'
    ), 1000);
  })
}

const testAsync = async () => {
  console.log(await fetchData1());
  console.log(await fetchData2());
  console.log(await fetchData3());
}

function* testGenerator() {
  console.log(yield fetchData1());
  console.log(yield fetchData2());
  console.log(yield fetchData3());
}

const asyncFn = generatorWrapper(testGenerator);
asyncFn().then().catch(e => console.log(`err:---------------${e}`));